package com.burpee.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.FoodSchedule;
import com.burpee.ui.GroupMember;

@Repository(value="groupmemberDao")
public class GroupMemberDaoImpl implements GroupMemberDao {
	
	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}

	public List<GroupMember> list(long groupNo) {
		List<GroupMember> list = null;

		try {
			list = sqlSessionTemplate.selectList("groupmemberlist",groupNo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	public GroupMember view(GroupMember groupMember) {
		GroupMember groupmemberview = new GroupMember();

		try {
			groupmemberview = sqlSessionTemplate.selectOne("groupmemberview", groupMember);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return groupmemberview;
	}

	public int add(GroupMember groupMember) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("groupmemberadd",groupMember);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int modify(GroupMember groupMember) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("groupmembermodify",groupMember);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int remove(GroupMember groupMember) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.delete("groupmemberremove",groupMember);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
